<?php
function V_LoadSearchView(&$arraySearch,$hinhthucthanhtoan,$mahoadon,$trangthaidonhang){
	$ulr = "?".MODUL."=hoadon&".ACTION."=";
	
	
?>
<?= CM_showError() ?>

<div style="padding-left:15px; ">
<font size="4" color="#FF0000">Kết quả tìm kiếm</font> <br>
<hr width="40%" size="1" align="left">
</div>
<?

    	//phan trang
    	$totalRows = 0;
		$paging="";
		$totalRows=count($arraySearch);
		$maxRows = MAXROW;
		$maxPages =MAXPAGES;
		if($totalRows%$maxRows==0)
			$totalPages = (int)($totalRows/$maxRows);
		else
			$totalPages = (int)($totalRows/$maxRows+1);
		$curPage =CM_getParameter("curPg");
		if($curPage=="")
			$curPage =1;
		else
			$curRow = ($curPage-1)*$maxRows+1;
		$paging ="Trang thứ :&nbsp;<font color=red>".$curPage."</font>&nbsp;&nbsp;&nbsp;"."Tổng số trang :&nbsp;<FONT color=red>".$totalPages."</FONT><br> ";
		if($totalRows>$maxRows)
		{
			$start=1;
			$end=1;
			$paging1 ="";
			for($i=1;$i<=$totalPages;$i++)
			{
				if(($i>((int)(($curPage-1)/$maxPages))* $maxPages) && ($i<=((int)(($curPage-1)/$maxPages+1))* $maxPages))
				{
					if($start==1) $start=$i;
						if($i==$curPage)
							$paging1 .=  $i."&nbsp;&nbsp;";
						else
							$paging1 .= "<a href='javascript:GotoPage(".$i.")'>".$i."</a>&nbsp;&nbsp;";
					$end=$i;
				}
			}
			$paging.= "Chọn trang :&nbsp;&nbsp;" ;
			if($curPage>$maxPages)
				$paging .="<a href='javascript:GotoPage(".($start-1).")'>Trở về</a>&nbsp;&nbsp;";
			$paging.=$paging1;
			if(((($curPage-1)/$maxPages+1)*$maxPages) < $totalPages)
				$paging .= "<a href='javascript:GotoPage(".($end+1).")'>Tiếp</a>&nbsp;&nbsp;";
		}
?>
<script>
function GotoPage(iPage){
	document.frm.action =document.frm.action  + "&curPg="+iPage;
	document.frm.submit()  ;
}

function ViewBill(mahoadon)
{
		// Create a random number 
	
	var ran_number= Math.random()*5;  

	strUrl = "../../run/printhd.php?mahoadon=" + mahoadon;

	window.open(strUrl,'name','height=800,width=900,toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no, resizable=no');

	return true;    

}

</script>
<table width="97%" align="center">
  <tr><td>

<form name="frm" action="<?=$ulr?>SearchHD&mahd=<? echo $mahoadon; ?>&tt=<?=$hinhthucthanhtoan?>&status=<?=$trangthaidonhang?>"  
method="post" enctype="multipart/form-data" >
<input type="hidden" name="mahoadon" value="<? echo $mahoadon; ?>">
<input type="hidden" name="hinhthucthanhtoan" value="<?=$hinhthucthanhtoan?>">
<input type="hidden" name="trangthaidonhang" value="<?=$trangthaidonhang?>">
<DIV style="BORDER-RIGHT: #999999 1px solid; VERTICAL-ALIGN: top; OVERFLOW: auto; BORDER-LEFT: #999999 1px solid; WIDTH: 100%px; BORDER-BOTTOM: #999999 1px solid; HEIGHT: 400px" align="center">
<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
<TBODY>
		   <TR align="center" bgcolor="#FFE59F">
				<TD width="27" align="center"><font size="2"><strong>STT</strong></font></TD>
				<TD width="139" align="center"><font size="2"><strong>Xem hóa đơn</strong></font></TD>  
				<TD width="544" align="left"><font size="2"><strong>Mã hóa đơn</strong></font></TD>
				<TD width="229" align="center"><font size="2"><strong>Trạng thái hóa đơn</strong></font></TD>
				<TD width="217" align="right"><font size="2"><strong>Ngày đặt hàng</strong></font></TD>
			</TR>
	<?
	//=======================================================================================
	if(count($arraySearch)>0)
	{
		$i=0;
		$low=$curRow;
		$curRow=1;
		$stt=0;
		foreach($arraySearch as $row)
		{
			$stt+=1;
			
			if(($curRow <= $totalRows) && ($curRow <= $curPage*$maxRows))
			{
				$str_trangthai = "";
				if($row["trangthaidonhang"]=='1'){
					$str_trangthai = 'Đặt hàng';
				} else{
					$str_trangthai = 'Đã thanh toán';
				}
				$curRow++;
				if($curRow>$low){
					$i+1;
	?>
					 <TR> 
					  	<TD align=middle class=bk12-140 bgcolor="#FFE59F"><font size="2"><?=$stt?></font></TD> 
						<TD width="139" align="center" class=bk12-140 bgcolor="#FFE59F">
							<img src="../images/xem.gif" width=19 border=0 onclick="ViewBill('<?=$row['mahoadon']?>');" style="cursor:pointer; ">						
						</TD>
						
						<TD width="544"class=bk12-140 align="left">
							<font size="2"><? echo $row['mahoadon']; ?>	 </font>
						</TD>        
						<TD width="229" class=bk12-140 align="center"><font size="2">
						<a class="thanh_link" 
						href="<?=$ulr."Edit_ht"?>&id=<? echo  $row['idhoadon']; ?>&trangthaidonhang=<? echo $row['trangthaidonhang'];?>&hd=<?=$mahd?>&curPg=<?=CM_getParameter("curPg");?>">
							<? echo $str_trangthai; ?>
						</a></font>
						</TD>
						<TD width="217" class=bk12-140 align="right"><font size="2"><?=date("d/m/Y H:s",$row['ngaydathang'])?></font></TD>
					  </TR>	
	  
	 <?
				} // end if($curRow>$low)
			}// end if(($curRow <= $totalRows) && ($curRow <= $curPage*$maxRows))
		} // end foreach($arrayData as $row)
	} // end if($arrayData>0)
	else
	{
?>
	  <tr valign="top">
			<td colspan=5 valign=center align="center"><b><font face="Arial" color="#FF0000">Không có bản ghi nào </font></b></td>
      </tr>
      <?php
		}
	  ?>

</TBODY>
</TABLE>

</div>

<table border="0" width="99%">
				<!--DWLayoutTable-->
				
				<tr>
				    <td width="363" rowspan="2" align=left>
					  <div align="left"><font face="Arial" color="#0066cc">Tổng số bản ghi <b><font color="#ff0000">
						<? echo($totalRows);?></font></b></font></div>
						 <hr width="40%" size="1" align="left">		  
				    </td>
				    <td width="565" height="23" align=right valign="top"><?=$paging?></td>
				</tr>
				<tr>
				   <td height="15" align="right" valign="top">
				 	<A class="thanh_link1" href="<?=$ulr."list" ?>">[<strong>Trở về </strong>]</a>&nbsp;&nbsp;&nbsp; 
				   </td>			 
				</tr>
</table>
<input type=hidden name="<?=ACTION2?>" value="<?=CM_getParameter(ACTION2)?>"> 
<input type=hidden name="textfield" value="<?=CM_getParameter("textfield")?>"> 
<input type=hidden name="cat_idS" value="<?=CM_getParameter("cat_idS")?>">
<input type=hidden name="tt" value="<?=CM_getParameter("tt")?>"> 
<input type=hidden name="curPg" >
</form>
</td></tr></table>

<?php
}
?>